//
//  publishController.m
//  ForengnMenu
//
//  Created by jiangtao on 16/1/23.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "publishController.h"
#import "publishoneCell.h"

@interface publishController ()<UITableViewDelegate,UITableViewDataSource,UIPickerViewDataSource,UIPickerViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *mytableView;

@property NSString * identifier;

@property NSString * huaLabel;

@property UIView * footView;

@property NSArray * titleArray;


@property (weak, nonatomic) IBOutlet UITableView *myTabelView;

@end

@implementation publishController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"发布话题";

    UIButton * rightbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightbutton setTitle:@"发布" forState:UIControlStateNormal];
    rightbutton.frame = CGRectMake(0, 0, 40, 30);
    
    [rightbutton setTitleColor:[UIColor colorWithRed:248/255.0f green:102/255.0f blue:79/255.0f alpha:1.0f] forState:UIControlStateNormal];
    rightbutton.titleLabel.font = [UIFont systemFontOfSize:16];
    [rightbutton addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightbutton];
    
    UIButton * left = [UIButton buttonWithType:UIButtonTypeCustom];
    [left setTitle:@"取消" forState:UIControlStateNormal];
    left.frame = CGRectMake(0, 0, 40, 30);
    left.titleLabel.font = [UIFont systemFontOfSize:16];
    [left setTitleColor:[UIColor colorWithRed:248/255.0f green:102/255.0f blue:79/255.0f alpha:1.0f] forState:UIControlStateNormal];
    
    [left addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:left];

    self.mytableView.backgroundColor = [UIColor colorWithRed:246/255.0f green:247/255.0f blue:239/255.0f alpha:1.0f];
    
    self.mytableView.tableFooterView = [UIView new];
    
    
    self.titleArray = @[@"西餐",@"法国大餐",@"日本料理",@"美国大餐",@"韩国料理",@"意大利大餐",@"墨西哥菜",@"东南亚菜"];
    
}

-(void)leftAction{

    [self.navigationController popViewControllerAnimated:YES];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        self.identifier = @"Cell1";
        publishoneCell * cell = [tableView dequeueReusableCellWithIdentifier:self.identifier];
        
        if (self.huaLabel !=nil) {
            cell.huaTiLabel.text = self.huaLabel;
            cell.huaTiLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1.0];
        }else{
            cell.huaTiLabel.text = @"请选择话题小组";
        }
        return cell;
    }else if (indexPath.row==1){
        self.identifier = @"Cell2";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:self.identifier];
        
        return cell;
    }else if (indexPath.row==2){
        self.identifier = @"Cell3";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:self.identifier];
        
        return cell;
    }else if (indexPath.row==3){
        self.identifier = @"Cell4";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:self.identifier];
        
        return cell;
    }else{
        self.identifier = @"Cell5";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:self.identifier];
        
        return cell;
    }

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        return 46;
    }else if (indexPath.row==1){
        return 46;
    }else if (indexPath.row==2){
        return 104;
    }else if (indexPath.row==3){
        return 43;
    }else{
        return 90;
    }
    
}
//发布按钮
-(void)rightAction{
    
    [self.navigationController popViewControllerAnimated:YES];

    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row==0) {
        
        _footView = [[UIView alloc]initWithFrame:CGRectMake(0,568, 320, 250)];
        
        _footView.backgroundColor =[ UIColor colorWithWhite:0.1 alpha:0.1];
        
        UIPickerView * pickerView = [UIPickerView new];
        pickerView.frame = CGRectMake(0, 0, 320, 250);
        pickerView.delegate = self;
        pickerView.dataSource = self;
        
        [_footView addSubview:pickerView];
        
        [UIView animateWithDuration:0.8 animations:^{
            
            CGRect rect = _footView.frame;
            rect.origin.y = 568-250;
            
            _footView.frame = rect;
            
            [self.view addSubview:_footView];
        }];
        
        UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(260, 10, 50, 30)];
        
        button.backgroundColor = [UIColor colorWithRed:248/255.0f green:102/255.0f blue:79/255.0f alpha:1.0f];
        [button setTitle:@"完成" forState:UIControlStateNormal];
        button.layer.cornerRadius = 4.0f;
        button.layer.masksToBounds =YES;
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(butonAction) forControlEvents:UIControlEventTouchUpInside];
        [_footView addSubview:button];
    }
}
-(void)butonAction{

    [UIView animateWithDuration:0.8 animations:^{
        
        CGRect rect = _footView.frame;
        rect.origin.y = 568;
        
        _footView.frame = rect;
        
    }];
    
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.titleArray.count;
}

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    return self.titleArray[row];
    
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    
    self.huaLabel = self.titleArray[row];
    
    [self.myTabelView reloadData];
}


@end
